#include <rclcpp/rclcpp.hpp>
#include <rcl_interfaces/msg/set_parameters_result.hpp>
// #include <string>
// #include <vector>

class SimpleParameter : public rclcpp::Node
{
public:
    SimpleParameter()
        : Node("simple_parameter")
    {
        RCLCPP_INFO(this->get_logger(), "SimpleParameter");
        this->declare_parameter<int>("int_param", 42);
        this->declare_parameter<std::string>("string_param", "default_string");
        parameters_callback_handle_ = add_on_set_parameters_callback(
            std::bind(&SimpleParameter::on_parameter_change, this, std::placeholders::_1));
    }

private:
    OnSetParametersCallbackHandle::SharedPtr parameters_callback_handle_;
    rcl_interfaces::msg::SetParametersResult on_parameter_change(
        const std::vector<rclcpp::Parameter> &parameters)
    {
        rcl_interfaces::msg::SetParametersResult result;
        for (const auto &parameter : parameters)
        {
            if (parameter.get_name() == "int_param")
            {
                int new_value = parameter.as_int();
                RCLCPP_INFO(this->get_logger(), "Parameter changed: %s", std::to_string(new_value).c_str());
                result.successful = true;
            }
            if (parameter.get_name() == "string_param")
            {
                RCLCPP_INFO(this->get_logger(), "Parameter changed: %s", parameter.value_to_string().c_str());
                result.successful = true;
            }
        }
        return result;
    }
};

int main(int argc, char *argv[])
{
    rclcpp::init(argc, argv);
    auto node = std::make_shared<SimpleParameter>();
    rclcpp::spin(node);
    rclcpp::shutdown();
    return 0;
}